/**
 * @file Body_Heath_Sensor.h
 * @brief human body health monitoring sensor
 * @author achdu0000@163.com
 * @version 1.0.0
 * @date 2024/07/01
 */

#ifndef _BODY_HEALTH_SENSOR_H_
#define _BODY_HEALTH_SENSOR_H_

#include "Arduino.h"

#define uint8_t unsigned char

/**
 * @brief Use Serial1 on Arduino GIGIA R1
 * @details 
 * - Serial1 pins:
 *      0 -> RX ,  1 <- TX
 * - Serial2 pins:
 *     19 -> RX1, 18 <- TX1
 * - Serial3 pins: 
 *     17 -> RX2, 16 <- TX2
 * - Serial4 pins:
 *     15 -> RX3, 14 -> TX3
 */
#define _BODY_HEALTH_SERIAL Serial1

/** send start sequence */
#define SEND_START_SEQ()    \
    ;                       \
    {                       \
        _BODY_HEALTH_SERIAL.write(0xA5); \
        _BODY_HEALTH_SERIAL.write(0xA1); \
    } 
/** send end sequence */
#define SEND_END_SEQ()      \
    ;                       \
    {                       \
        _BODY_HEALTH_SERIAL.write(0xA5); \
        _BODY_HEALTH_SERIAL.write(0xA2); \
    }

/**
 * @brief human body health monitoring sensor data structure(totally, 16 bytes)
 */
typedef struct
{
    uint8_t head[2];            ///< available head: 0xff, 0x01
    uint8_t heartRate;
    uint8_t bloodOxygen;
    uint8_t microcirculation;
    uint8_t bloodPressure[2];   ///< blood pressure high, low
    uint8_t R2RInterval;
    uint8_t HRV_SDNN;
    uint8_t HRV_RMSSD;
    uint8_t fatigue;
    uint8_t ambientTemp[2];     ///< ambient temperture t (°C): [t], t-[t]
    uint8_t bodyTemp[2];        ///< body temperture    t (°C): [t], t-[t]
    uint8_t tail;               ///< available tail: 0xf1
} BodyHeathSensor;

/**
 * check if the head of BodyHeathSensor is available
 * @param[in] BodyHeathSensor bhs
 * @return [true]: available, [false]: unavailable
 */
bool isAvailable(BodyHeathSensor bhs);


/**
 * @brief setup the config and be used in .ino setup()
 */
void myBodyHealthSensorSetup();

/**
 * @brief use for func myBodyHealthSensorLoop()
 * @details determine whether to SEND_START_SEQ() in ...Loop()
 */
inline bool sendStartSeqFlag = true; 

/**
 * @brief get the data from sensor and be used in .ino loop() 
*/
void myBodyHeathSensorLoop();

#endif //!_BODY_HEALTH_SENSOR_H_
